<template>
	<view class="fui-wrap">
		<fui-sticky>
			<view style="background-color: #fff;">
				<fui-segmented-control :height="84" @click="changeSegmented" :current="current" color="#000" activeColor="#0a8cdd" type="text" :values="segmented"></fui-segmented-control>
			</view>
		</fui-sticky>
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index" arrow @click="clickItem(item,index)">
				<view class="item">
					<view class="leftbox">
						<view class="line">
							<fui-tag :text="item.order_type_text" type="primary"></fui-tag>
						</view>
						<view class="line">
							<fui-text text="时间：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.pay_time" color="#000" :size="28"></fui-text>
						</view>
						<view class="line">
							<fui-text text="单号：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.out_trade_no" color="#000" :size="28"></fui-text>
						</view>
						<view class="line">
							<fui-text text="手续费：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="'￥'+parseNumber(item.handling_fees/100)" color="#000" :size="28"></fui-text>
						</view>
						<view class="line">
							<fui-text text="商品详情：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.detail" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="status">
						<fui-tag :text="'￥'+parseNumber(item.pay_price)" type="success"></fui-tag>
						<fui-tag v-if="item.refund_price" :text="'退￥'+parseNumber(item.refund_price)" type="danger"></fui-tag>
					</view>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<fui-modal :show="act.show" descr="请选择操作" v-if="buttons" :buttons="buttons" :radius="16" :maskClosable="true" direction="column" @click="clickButton" @cancel="cancelButton"></fui-modal>
		<filter :param="param" @confirm="doSubmit"></filter>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDuration,parseNumber} from '@/utils/util.js'
	import filter from '@/components/common/filter.vue';
	export default {
		components:{
			filter:filter
		},
		data() {
			return {
				baseUrl:baseUrl,
				segmented:['线上支付','线下支付'],
				segmented_type:['online','underline'],
				current:0,
				list:[],
				page:1,
				endData:false,
				act:{
					show:false,
					index:'',
					item:''
				},
				buttons:'',
				param:{
					plate_number:'',
					out_trade_no:'',
					transaction_id:'',
					starttime:'',
					endtime:''
				}
			}
		},
		onLoad(e) {
			this.getList();
		},
		onShow() {
			let refresh=uni.getStorageSync('refresh') || '';
			if(refresh){
				this.list=[];
				this.page=1;
				this.endData=false;
				uni.setStorageSync('refresh','');
				this.getList();
			}
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			formatDuration,
			parseNumber,
			changeSegmented:function(e){
				this.current=e.index;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			clickItem:function(item,index){
				let buttons=[
					{
						text: '退款',
						background: '#ff0000',
						value:'refund'
					}
				];
				if(item.order_type=='parking'){
					buttons.push({
						text: '停车详情',
						background: '#19a4d6',
						value:'detail'
					});
				}
				this.buttons=buttons;
				this.act={
					show:true,
					item:item,
					index:index
				};
			},
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('parking/finance/list',{
					...this.param,
					pay_type:this.segmented_type[this.current],
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			},
			clickButton:function(e){
				let item=this.act.item;
				let index=this.act.item.index;
				if(e.value=='refund'){
					uni.setStorageSync('pay_detail',this.act.item);
					this.$navigateTo('parking/finance/refund');
				}
				if(e.value=='detail'){
					this.$navigateTo('parking/records/detail?records_id='+item.records_id);
				}
				this.cancelButton();
			},
			cancelButton:function(){
				this.buttons='';
				this.act={
					show:false,
					index:'',
					item:''
				};
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	width: 100%;
	display: flex;
	justify-content: space-between;
	align-items: center;
	.leftbox{
		width: 75%;
		.line{
			height: 50rpx;
			line-height: 50rpx;
		}
	}
	.status{
		width: 25%;
		text-align: right;
		display: flex;
		flex-direction: column;
	}
}
</style>